#!/usr/bin/env perl

use strict;
use warnings;
use bytes;

while (<>) {

    s{\s\[ ( [^\[\s]+ ) \]\s }{" `[`$1`]` "}gixe;

    s{ \[\[ ( [^\]\|]+ ) \| ([^\]]*) \]\] }{"[$1 $2]"}gixe;

    s{'''(.*?)'''}{"`$1`"}ge;
    s{''(.*?)''}{"_$1_"}ge;

    s{^\s*<[^/>]+>\s*$}{\{\{\{\n};
    s{^\s*</[^/]+>\s*$}{\}\}\}};

    if (/^\s*$/) {
        print "\n";
        next;
    }

    s{^\*}{ \*};
    s{^\#}{ \#};

    print $_;
}

